package hz.mobileproject.pda.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Response_gridPerson_item;
import hz.mobileproject.pda.entity.response.Response_noneProcess_item;

/**
 * Created by Lc on 2017/10/25.
 */

public class GridPersonsAdapter extends BaseAdapter {
    private Context mContext;
    private List<Response_gridPerson_item> listData;
    private LayoutInflater inflater;

    public GridPersonsAdapter(Context mContext, List<Response_gridPerson_item> listData) {
        this.mContext = mContext;
        this.listData = listData;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item_grid_person_inlv,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_person_name.setText(listData.get(position).getPrisoner_name());

        return convertView;
    }

    public void setListData(ArrayList<Response_gridPerson_item> listData){
        if(listData == null){
            listData = new ArrayList<Response_gridPerson_item>();
        }
        this.listData = listData;
        notifyDataSetChanged();
    }

    public List<Response_gridPerson_item> getListData() {
        return listData;
    }

    private class ViewHolder{
        private TextView tv_person_name;

        public ViewHolder(View v) {
            tv_person_name = (TextView)v.findViewById(R.id.tv_person_name);
        }
    }
}
